import wmx from "@/common/wmx";
import moment from 'moment'
export default {
  install(app) {
    let tools = this.init();
    app.config.globalProperties.$tools = tools;
    app.config.globalProperties.$moment = moment();
  },
  init() {
    //树结构扁平化
    function flatten(data, sub = "children") {
      return data.reduce(
        (arr, obj) => arr.concat([obj], this.flatten(obj[sub])),
        []
      );
    }

    // 不刷新页面修改路由地址
    function addUrlParameter(query) {
      // 获取当前URL
      var url = window.location.href;
      // 修改query参数
      var newQuery = query;
      // 拼接新的URL
      var newUrl = url.split("?")[0] + "?" + newQuery;
      // 修改地址栏URL
      history.pushState(null, null, newUrl);
    }
    return {
      flatten
    };
  },
};
